package org.bao.demo.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName Producer
 * @Description 消息生产者
 * @Author bai
 * @Date 2021/7/20 23:40
 * @Version 1.0
 **/
public class Producer {



    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = MqFactory.getConnection();

        Channel channel = connection.createChannel();
        channel.queueDeclare(Common.QUEUE_NAME, false, false, false, null);

        final String message = "hello World!";

        channel.basicPublish("", Common.QUEUE_NAME, null, message.getBytes());
        System.out.println("消息发送完毕");

        channel.close();
        connection.close();

    }



}
